<?php
	require_once 'database.php';
	if (isset($_GET[u1]) && isset($_GET[u2]) && isset($_GET[teks]))
	{
		database::query("INSERT INTO chat (User1, User2, Waktu, Teks) VALUES ('".$_GET[u1]."', '".$_GET[u2]."', CURRENT_TIMESTAMP, '".$_GET[teks]."')");
		//echo $_GET[u1].' '.$_GET[u2].' '.$_GET[teks]."beres deh";
	}
	else if (isset($_GET[s1]) && isset($_GET[s2]) && isset($_GET[u1]) && isset($_GET[u2]))
	{
		$hasil = database::query("SELECT * FROM chat WHERE ((User1 = '".$_GET[u1]."' AND User2 = '".$_GET[u2]."')OR(User1 = '".$_GET[u2]."' AND User2 = '".$_GET[u1]."')) ORDER BY ID DESC LIMIT 20");
		$i = mysql_num_rows($hasil);
		while ($i-->0)
		{
			$baris = mysql_fetch_array($hasil);
			
			echo '<tr><td class= "box" valign = "top" colspan=3><form action="php/posting.php" method="post" name="postingan">';
			if (strcmp($baris[1], $_GET[u1])==0)
				echo '<table><tr><td><img src="'.$_GET[s1].'" width = 80 height = 80/></td>';
			else
				echo '<table><tr><td><img src="'.$_GET[s2].'" width = 80 height = 80/></td>';
			echo '<td>Post #'.$baris[0].', Date : '.$baris[3].'<br/><textarea cols = 62 rows = 2 disabled="disabled">'.$baris[4].'</textarea></td></tr></table>';
			echo '</form></td></tr>';
		}
	}
	else
		echo "";
?>